﻿Imports HMSLibrary
Imports HMSDataLayer

Public Class CompanyInfoControl
    Implements IHMSData

    Public Property ID As Integer Implements HMSLibrary.IHMSData.ID
    Public Function DataValidation() As Boolean Implements HMSLibrary.IHMSData.DataValidation

    End Function

    Public Sub LoadData(ByVal ID As Integer) Implements HMSLibrary.IHMSData.LoadData
        Try
            Dim DataObject As New MasterDataLayer()
            Dim CompanyObject As CompanyInfo = Nothing
            CompanyObject = DataObject.GetCompanyInfo
            If CompanyObject IsNot Nothing Then
                NameTextBox.Text = CompanyObject.Name
                AddressTextBox.Text = CompanyObject.Address
                DescriptionTextBox.Text = CompanyObject.Description
                TelNo1TextBox.Text = CompanyObject.TelNo
                VATNoTextBox.Text = CompanyObject.VATNo
                CSTNoTextBox.Text = CompanyObject.CSTNo
                InvoiceTermTextBox.Text = CompanyObject.InvoiceTerm
                ItemNoToggleSwitch.IsChecked = CompanyObject.ItemNoAuto
                'POCurrentNoTextBox.Text = CompanyObject.POCurrentNo
                'POPrefixTextBox.Text = CompanyObject.POPrefix
                'POSufixTextBox.Text = CompanyObject.POSufix
                SalesBillPrefixTextBox.Text = CompanyObject.SalesBillPrefix
                SalesCurrentNoTextBox.Text = CompanyObject.SalesCurrentNo
                SalesSufixTextBox.Text = CompanyObject.SalesSufix
            End If
        Catch ex As Exception
            AppCommon.LogError(ex)
        End Try
    End Sub

    Public Function SaveData() As Boolean Implements HMSLibrary.IHMSData.SaveData
        If FormValidation() = False Then Return False
        Dim dataProvider As New MasterDataLayer()
        Dim com As New CompanyInfo
        com.Name = NameTextBox.Text.Trim
        com.Address = AddressTextBox.Text.Trim
        com.CSTNo = CSTNoTextBox.Text.Trim
        com.Description = DescriptionTextBox.Text.Trim
        com.InvoiceTerm = InvoiceTermTextBox.Text.Trim
        com.ItemNoAuto = ItemNoToggleSwitch.IsChecked
        'com.POCurrentNo = POCurrentNoTextBox.Text.Trim
        'com.POPrefix = POPrefixTextBox.Text.Trim
        'com.POSufix = POSufixTextBox.Text.Trim
        com.SalesBillPrefix = SalesBillPrefixTextBox.Text.Trim
        com.SalesCurrentNo = SalesCurrentNoTextBox.Text.Trim
        com.SalesSufix = SalesSufixTextBox.Text.Trim
        com.TelNo = TelNo1TextBox.Text.Trim
        com.VATNo = VATNoTextBox.Text.Trim
        dataProvider.SaveCompanyInfo(com)
        AppCommon.loginInfo.isItemNoAuto = ItemNoToggleSwitch.IsChecked
        Return True
    End Function

    Private Sub CompanyInfoUserControl_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        LoadData(0)
    End Sub

    Public Property ActionMode As HMSLibrary.FormAction Implements HMSLibrary.IHMSData.ActionMode

    Private Function FormValidation() As Boolean
        FormValidation = False
        Try
            If Trim(NameTextBox.Text) = "" Then
                CommonMessages.ShowValidationMsg("Please enter name!")
                Exit Function
            End If
            FormValidation = True
        Catch ex As Exception
            AppCommon.LogError(ex)
        End Try
    End Function

    Public Sub AddNew() Implements HMSLibrary.IHMSData.AddNew

    End Sub

    Public Sub FindData() Implements HMSLibrary.IHMSData.FindData
  
    End Sub

    Public Sub BackView() Implements HMSLibrary.IHMSData.BackView
 
    End Sub
End Class
